package com.cash.lemoloan.statisticlib.Utils;

import android.text.TextUtils;

import com.cash.lemoloan.statisticlib.OnWiFiListListener;
import com.cash.lemoloan.statisticlib.StatisticApplication;
import com.cash.lemoloan.statisticlib.StatisticContant;
import com.cash.lemoloan.statisticlib.StatisticUploadTask;
import com.cash.lemoloan.statisticlib.model.StatisticBaseUploadInfo;
import com.cash.lemoloan.statisticlib.model.StatisticDEV01Info;
import com.cash.lemoloan.statisticlib.model.StatisticRouterInfo;

import java.util.List;


public class StatisticUploadUtil {
    private static final String TAG = "Statistics ==> :";

    public static void uploadDev01(String number1, String number2, boolean numberP, boolean phoneP) {
        try {
            StatisticBaseUploadInfo<StatisticDEV01Info> baseUploadInfo = new StatisticBaseUploadInfo<StatisticDEV01Info>(StatisticContant.DEV01);
            StatisticDEV01Info dev01Info = new StatisticDEV01Info();
            dev01Info.setStatisticphoneNum(number1);
            dev01Info.setStatisticphoneNumber2(number2);
            dev01Info.setStatisticnumberP(numberP);
            dev01Info.setStatisticphoneP(phoneP);
            baseUploadInfo.setTotalPage("1");
            baseUploadInfo.setReqId(String.valueOf(System.currentTimeMillis()));
            baseUploadInfo.setCurrPage("1");
            baseUploadInfo.setTotalSize("1");
            baseUploadInfo.setData(dev01Info);
            long oldCtime = PreferencesUtil.getLong(StatisticContant.NEW_CASHUPLOAD_DEV01_TIME);
            if (oldCtime == -1 || (System.currentTimeMillis() - oldCtime) > StatisticContant.NEW_CASHMAX_INTERVAL) {
                StatisticUploadTask uploadTask = new StatisticUploadTask(StatisticContant.DEV01, baseUploadInfo);
                uploadTask.execute();
            } else {
            }
        } catch (Exception e) {
        }


    }

    public static void uploadCallLogs() {
        try {
            long oldCtime = PreferencesUtil.getLong(StatisticContant.NEW_CASHUPLOAD_CALL_LOG_TIME);
            if (oldCtime == -1 || (System.currentTimeMillis() - oldCtime) > StatisticContant.NEW_CASHMAX_INTERVAL) {
                StatisticUploadTask uploadTask = new StatisticUploadTask(StatisticContant.CALLLOG01, null);
                uploadTask.execute();
            } else {
            }
        } catch (Exception e) {
        }
    }

    public static void uploadContacts() {
        try {
            if (!TextUtils.isEmpty(StatisticContant.NEW_CASHUSER_GID)) {
                long oldCtime = PreferencesUtil.getLong(StatisticContant.NEW_CASHUPLOAD_CON01_TIME);
                if (oldCtime == -1 || (System.currentTimeMillis() - oldCtime) > StatisticContant.NEW_CASHMAX_INTERVAL) {
                    StatisticUploadTask uploadTask = new StatisticUploadTask(StatisticContant.CON01, null);
                    uploadTask.execute();
                } else {
                }
            }
        } catch (Exception e) {
        }


    }

    public static void uploadApp01() {
        try {
            long oldCtime = PreferencesUtil.getLong(StatisticContant.NEW_CASHUPLOAD_APP01_TIME);
            if (oldCtime == -1 || (System.currentTimeMillis() - oldCtime) > StatisticContant.NEW_CASHMAX_INTERVAL) {
                StatisticUploadTask uploadTask = new StatisticUploadTask(StatisticContant.APP01, null);
                uploadTask.execute();
            } else {
            }
        } catch (Exception e) {
        }
    }

    public static void uploadWifi01() {
        try {
            long oldCtime = PreferencesUtil.getLong(StatisticContant.NEW_CASHUPLOAD_WIFI01_TIME);
            if (oldCtime == -1 || (System.currentTimeMillis() - oldCtime) > StatisticContant.NEW_CASHMAX_INTERVAL) {
                DevicesUtil.startWiFiListScan(new OnWiFiListListener() {
                    @Override
                    public void onWiFiListResult(List<StatisticRouterInfo> routerList) {
                        DevicesUtil.stopWiFiListScan(StatisticApplication.getInstance());
                        if (routerList != null && routerList.size() > 0) {
                            StatisticBaseUploadInfo<List<StatisticRouterInfo>> baseUploadInfo = new StatisticBaseUploadInfo<List<StatisticRouterInfo>>(StatisticContant.WIFI01);
                            baseUploadInfo.setTotalPage("1");
                            baseUploadInfo.setReqId(String.valueOf(System.currentTimeMillis()));
                            baseUploadInfo.setCurrPage("1");
                            baseUploadInfo.setTotalSize(routerList.size() + "");
                            baseUploadInfo.setData(routerList);
                            StatisticUploadTask uploadTask = new StatisticUploadTask(StatisticContant.WIFI01, baseUploadInfo);
                            uploadTask.execute();
                        }

                    }
                });

            } else {
            }
        } catch (Exception e) {
        }

    }

}
